package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Caution;
import com.ayou.eggguard.farm.service.CautionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/caution")
public class CautionController {
    @Autowired
    private CautionService cautionService;

    @GetMapping("/getCautionList")
    public Result<PageBean<Caution>> getCautionList(Integer pageNum,
                                                    Integer pageSize,
                                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
                                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
                                                    @RequestParam(required = false) String cautionType,
                                                    @RequestParam(required = false) String cautionStatus,
                                                    @RequestParam(required = false) String coopNumber
                                                    ){
        PageBean<Caution> pb=cautionService.getCautionList(pageNum,pageSize,startTime,endTime,cautionType,cautionStatus,coopNumber);
        return Result.success(pb);
    }

    @GetMapping("/updateCautionStatus")
    public Result updateCautionStatus(Integer id){
        cautionService.updateCautionStatus(id);
        return Result.success();
    }


    @GetMapping("/getCautionTypeCount")
    public Result<List<Map<String,Object>>> getCautionTypeCount(){
        List<Map<String,Object>> list= cautionService.getCautionTypeCount();
        return Result.success(list);
    }

    @GetMapping("/getCautionCount")
    public Result<List<Map<String,Object>>> getCautionCount(){
        List<Map<String,Object>> list=cautionService.getCautionCount();
        return Result.success(list);
    }

}
